package servise.advert;

import java.util.ArrayList;
import java.util.List;

import pojo.advert.TblAdvert;

import vo.advert.AdvertVo;

import dao.advert.AdvertDao;

public class AdvertService {
	public AdvertVo uptTblAdvert(AdvertVo advertVo){
		AdvertVo advertVoQuery = new AdvertVo();
		TblAdvert tblAdvert;
		AdvertDao advertDao = new AdvertDao();
		tblAdvert = advertDao.uptTblAdvert(advertVo);
		
		advertVoQuery.setAdvertAddressId(tblAdvert.getAdvertAddressId());
		advertVoQuery.setId(tblAdvert.getId());
		advertVoQuery.setAdvertName(tblAdvert.getAdvertName());
		advertVoQuery.setAdvertPath(tblAdvert.getAdvertPath());
		advertVoQuery.setAvertType(tblAdvert.getAvertType());
		advertVoQuery.setNotes(tblAdvert.getNotes());
		
		return advertVoQuery;
	}
	public void deleteAdvert(String[] selectedId){
		if(selectedId==null||selectedId.length==0){
			return;
		}
		String ids = "'"+selectedId[0]+"'";
		for(int i=1;i<selectedId.length;i++){
			ids +=",'"+selectedId[i]+"'";
		}
		AdvertDao advertDao = new AdvertDao();
		advertDao.deleteTblAdver(ids);
	}
	public List<AdvertVo> searchAdvert(AdvertVo advertVo){
		AdvertDao advertDao = new AdvertDao();
		int totalItem = advertDao.getTblAdvertCount(advertVo);
		int totalPage = totalItem/advertVo.getSizePerPage() + (totalItem%advertVo.getSizePerPage()==0?0:1);
		advertVo.setTotal(totalPage);
		if(advertVo.getCurPage()==null||advertVo.getCurPage()==0){
			advertVo.setCurPage(1);
		}
		List<AdvertVo> advertVoList =new ArrayList();
		advertVoList = advertDao.getTblAdvert(advertVo);
		return advertVoList;
	}

}
